package com.basin.common.core.exception;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpStatus;

import java.io.Serial;
import java.io.Serializable;

/**
 * @author: Sam ZHONG | sammy1997@aliyun.com
 */
@EqualsAndHashCode(callSuper = true)
@Slf4j
@Data
public class BasinException extends RuntimeException implements Serializable {
    @Serial
    private static final long serialVersionUID = 1L;

    private int code;
    private String message;

    public BasinException(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public BasinException(String message) {
        this.code = HttpStatus.SC_INTERNAL_SERVER_ERROR;
        this.message = message;
    }

    public BasinException(Exception exception) {
        this.code = 500;
        this.message = exception.getMessage();
    }

    public <EX extends BasinExViewVO> BasinException(EX exCode) {
        this.code = exCode.getCode();
        this.message = exCode.getMessage();
    }
}
